package n1;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * 使用 Thread 和Runable创建线程
 */
@Slf4j(topic = "c.Test1")
public class T1_Thread_Runnable {

    public static void main(String[] args) {
        test1();
//        test2();
//        test2_1();
//        test2_2();
    }
    /*
    -------------------------------------
    |           第一代
    =====================================
    */
    public static void test1(){
        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                log.debug("hello");
            }
        };
        t1.start();
//        t1.run(); // run() 使用的是主线程
    }

    /*
    -------------------------------------
    |           第二代
    =====================================
    */
    public static void test2(){
        Runnable task2 = new Runnable() {
            @Override
            public void run() {
                log.debug("hello");
            }
        };
        Thread t2 = new Thread(task2, "t2");
        t2.start();
    }

    /*
    -------------------------------------
    |           第二代 lambda
    =====================================
    */
    public static void test2_1(){
        Runnable task2 = ()->log.debug("hello test2_1");
        Thread t2 = new Thread(task2, "t2");
        t2.start();
    }
    /*
    -------------------------------------
    |           第二代 lambda
    =====================================
    */
    public static void test2_2(){
        Thread t2 = new Thread(()->log.debug("hello test2_2"), "t2");
        t2.start();
    }

}